from PyQt4 import QtCore
from PyQt4.QtCore import QObject,QThread,pyqtSignal
import random
from KDataBase.KBuildDB import KBuildDB
from KDataBase.KUpdateDB import KUpdateDB
from KDataBase.KQueryDB import KQueryDB
from PyQt4.QtGui import QApplication
import datetime
import time
class KDBManager(QObject):
    ProgressUpdated=pyqtSignal(str)
    def __init__(self,parent=None):
        QObject.__init__(self)
    def PrepareForNewThread(self,db):
        self.db=db
        self.db.ProgressUpdated.connect(self.UpdateProgress)    
    def StopImport(self):
        if hasattr(self,'db') and self.db:
            self.db.Stop=True 
    def UpdateProgress(self,text):
        self.ProgressUpdated.emit(text)
    def ExecuteImportCommand(self,para):
        if para["Op"]=="Update":
            self.PrepareForNewThread(KUpdateDB())
            ##self.db.ProcessUpdateFile("D:/Dropbox/Trading2013/Data/ToUpdate/5_us_txt.zip","Stooq")
        else:
            self.PrepareForNewThread(KBuildDB())      
        self.db.ExectueCommandInThread(para)

        
